package com.yf.ref;

import com.yf.pojo.User;

import java.lang.ref.WeakReference;

public class WeakReferenceTest {
    public static void main(String[] args) {
        // 构造弱引用
        WeakReference<User> ref = new WeakReference<>(new User(1, "yvan"));
        // 从弱引用中重新获取对象
        System.out.println(ref.get());

        // 不管当前内存空间是否足够，都会回收仅弱引用可达对象
        System.gc();
        System.out.println("after GC: ");
        System.out.println(ref.get());
    }
}
